<%@page import="backpage.view.ResItem"%>
<%@page import="backpage.view.PageDivision"%>
<%@page import="com.model.User"%>
<%@page import="javassist.bytecode.stackmap.BasicBlock.Catch"%>
<%@page import="javax.xml.ws.RespectBinding"%>
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/backPage/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<base href="<%=basePath%>" />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />
	<meta http-equiv="keywords" content="" />
	<meta http-equiv="description"
		content="Teacher's entry for Software Engineering Course" />
	<title>Teacher's entry for Software Engineering Course</title>
	<link rel="stylesheet" type="text/css" href="css/backpage.css" />
	<script type="text/javascript" src="<%=basePath%>js/default.js"></script>
	<script type="text/javascript">
		function onSort(sk){	//sort requested
			var curSK = "<%=request.getParameter("sortKey")%>";
			if( curSK == "null" )
				curSK = "0fileName";
			if( curSK.substring(1,curSK.length) == sk ){
				if( curSK.charAt(0) == "0" )
					sk = "1" + sk;
					else sk = "0" + sk;
			}
			else sk = "0" + sk;
			document.getElementById("sortKey").value = sk;
			onSubmit();
		}
		
		function showDescription(id){
			var btn = document.getElementById("btn"+id).innerHTML;
			if( btn == "" || btn == "显示" ){
				document.getElementById("btn"+id).innerHTML = "隐藏";
				document.getElementById("table"+id).style.display = "";
			}else{
				document.getElementById("btn"+id).innerHTML = "显示";
				document.getElementById("table"+id).style.display = "none";
			}
		}
		
		function onDelete(){
			if( !document.getElementsByName("itemCheckBox") ){
				alert("No item selected~~");
				return;
			}
			var hasItem = false;
			if( document.getElementsByName("itemCheckBox").length ){
				for(  var i=0; i<document.getElementsByName("itemCheckBox").length; i++ ){
					document.getElementsByName("itemCheckBox")[i].value = document.getElementsByName("itemCheckBox")[i].id;	//send the indexes of the checkboxes to the controller
					if( document.getElementsByName("itemCheckBox")[i].checked )
						hasItem = true;
			}
			}
			else{
				document.getElementsByName("itemCheckBox").value = document.getElementsByName("itemCheckBox").id;
				if( document.getElementsByName("itemCheckBox").checked )
					hasItem = true;
			}
			if( !hasItem ){
				alert("No item selected~~");
				return;
			}else if( confirm("Are you sure to delete the item(s) selected?") ){
				(document.getElementById("mainContent")).action = "../deleteitems.servlet?resType=<%=request.getParameter("resType")%>";
				(document.getElementById("mainContent")).submit();
			}
		}
	
		function onAdd(){
			(document.getElementById("mainContent")).action = "jsp/upload.jsp?resType=<%=request.getParameter("resType")%>";
			(document.getElementById("mainContent")).submit();
		}
	</script>
  </head>
  
	<%
		PageDivision pageDivision = (PageDivision) request
				.getAttribute("pageDivision");
		if (pageDivision == null) {
			try {
				pageDivision = new PageDivision(1, 2, new ArrayList());
				if (request.getParameter("resType") == null)
					response.sendRedirect("../itemlist.jsp?resType=doc");
				else
					response.sendRedirect("../itemlist.jsp?resType="
							+ request.getParameter("resType"));
			} catch (Exception e) {
				System.out.println(e);
			}
		}
	%>

	<body>

		<div id="Header">

			<div id="Logon">
				<div id="Logon">
					<form action="backlogin" namespace="/">
						<table>
							<tr>
								<td>
									欢迎您，
									<s:property value="#session.userInfo.getName()" />
								</td>
								<td class="seperator"></td>
								<td>
									<a href="../backlogin!logout.action">退出</a>
								</td>
							</tr>
						</table>
					</form>
				</div>
			</div>

			<div id="Logo">
				<img src="<%=basePath%>img/logo.png" alt="南开大学" align="center" />
			</div>

			<div id="Navigation">
				<table>
					<tr>
						<td id="nav_doc">
							<a href="?resType=doc" style="font-family: '微软雅黑';">教学课件</a>
						</td>
						<td id="nav_video">
							<a href="?resType=video" style="font-family: '微软雅黑';">教学视频</a>
						</td>
						<td id="nav_software">
							<a href="?resType=software" style="font-family: '微软雅黑';">教学软件</a>
						</td>
						<td id="nav_reference">
							<a href="?resType=reference" style="font-family: '微软雅黑';">参考资料</a>
						</td>
						<td id="nav_notice">
							<a href="../notices!showNotices.action" style="font-family: '微软雅黑';">课程通知</a>
						</td>
						<td id="nav_exam">
							<a href="jsp/addexam.jsp" style="font-family: '微软雅黑';">题目管理</a>
						</td>
					</tr>
				</table>
				<script type="text/javascript">
				navClicked("<%=request.getParameter("resType")%>");
			</script>

			</div>
		</div>

		<div id="MainContent">
			<form id="mainContent"
				action="../itemlist.jsp?resType=<%=request.getParameter("resType")%>"
				method="post">

				<div id="TopLine"></div>

				<table border="0">
					<tr>

						<td valign="top" class="content_left">
							<div id="Menu">
								<div id="MenuTop"></div>
								<div id="MenuMid">

									<div id="MenuUnit" class="search">
										<ul>
											<li>
												检索字段
												<input id="keyWord" name="keyWord" type="text" />
											</li>
											<li>
												字段类型
												<select id="wordType" name="wordType">
													<option value="all">
														所有
													</option>
													<option value="file_name">
														文件名
													</option>
													<option value="create_time">
														创建时间
													</option>
													<option value="description">
														描述
													</option>
												</select>
											</li>
											<li>
												检索范围
												<select id="searchScope" name="searchScope">
													<option value="<%=request.getParameter("resType")%>">
														当前选项卡
													</option>
													<option value="all">
														所有资源
													</option>
													<%
														if (request.getParameter("resType") != null
																&& !request.getParameter("resType").equals("doc")) {
													%>
													<option value="doc">
														教学课件
													</option>
													<%
														}
													%>
													<%
														if (request.getParameter("resType") != null
																&& !request.getParameter("resType").equals("video")) {
													%>
													<option value="video">
														教学视频
													</option>
													<%
														}
													%>
													<%
														if (request.getParameter("resType") != null
																&& !request.getParameter("resType").equals("software")) {
													%>
													<option value="software">
														教学软件
													</option>
													<%
														}
													%>
													<%
														if (request.getParameter("resType") != null
																&& !request.getParameter("resType").equals("reference")) {
													%>
													<option value="reference">
														参考资料
													</option>
													<%
														}
													%>
												</select>
											</li>
											<li class="center">
												<input type="submit" onclick="onSearch()" value="检索" />
											</li>
										</ul>
										<script type="text/javascript">
									<%String keyWord = request.getParameter("keyWord");
			if (keyWord == null)
				keyWord = "";
			String wordType = request.getParameter("wordType");
			if (wordType == null)
				wordType = "all";
			String searchScope = request.getParameter("searchScope");
			if (searchScope == null)
				searchScope = request.getParameter("resType");
			if (searchScope == null || searchScope.equals("null"))
				searchScope = "doc";
			System.out.println(keyWord + "  " + wordType + "  " + searchScope);%>
									document.getElementById("keyWord").value = "<%=keyWord%>";
									document.getElementById("wordType").value = "<%=wordType%>";
									document.getElementById("searchScope").value = "<%=searchScope%>";
								</script>
									</div>

									<div id="MenuUnit" class="catalogue">
										<ul>
											<li>
												<a href="">默认归档</a>
											</li>
										</ul>
									</div>
								</div>
								<div id="MenuBottom"></div>
							</div>
						</td>

						<td valign="top" class="content_right">
							<div id="CntHeader">
								<div id="CntHeader" class="left">
									<select name="numInOnePage" id="numInOnePage">
										<option value="10" onclick="onSubmit()">
											每页显示10个
										</option>
										<option value="20" onclick="onSubmit()">
											每页显示20个
										</option>
										<option value="30" onclick="onSubmit()">
											每页显示30个
										</option>
									</select>
									<script type="text/javascript">
									<%String v = request.getParameter("numInOnePage");
			if (v == null)
				v = "20";%>
									document.getElementById("numInOnePage").value = <%=v%>;
								</script>
								</div>

								<div id="CntHeader" class="right">
									<%
										if (pageDivision != null && pageDivision.getCurPage() <= 1) {
									%>
									<a style="cursor: default;"> <img align="absmiddle"
											src="img/arrow_first_i.gif" /> </a>
									<a style="cursor: default;"> <img align="absmiddle"
											src="img/arrow_left_i.gif" /> </a>
									<%
										} else {
									%>
									<a onclick="onPage(1,<%=pageDivision.getTotalPageNum()%>)">
										<img align="absmiddle" src="img/arrow_first.gif" /> </a>
									<a
										onclick="onPage(<%=pageDivision.getCurPage() - 1%>,<%=pageDivision.getTotalPageNum()%>)">
										<img align="absmiddle" src="img/arrow_left.gif" /> </a>
									<%
										}
									%>
									<img align="absmiddle" src="img/spacer.png" />
									当前页
									<input type="text" style="width: 20px;" name="curPage"
										id="curPage" value="<%=pageDivision.getCurPage()%>" />
									/<%=pageDivision.getTotalPageNum()%>
									<a onclick="onPageInput(<%=pageDivision.getTotalPageNum()%>)">
										<img align="absmiddle" src="img/go.gif" /> </a>
									<img align="absmiddle" src="img/spacer.png" />
									<%
										if (pageDivision != null
												&& pageDivision.getCurPage() >= pageDivision
														.getTotalPageNum()) {
									%>
									<a style="cursor: default;"> <img align="absmiddle"
											src="img/arrow_right_i.gif" /> </a>
									<a style="cursor: default;"> <img align="absmiddle"
											src="img/arrow_last_i.gif" /> </a>
									<%
										} else {
									%>
									<a
										onclick="onPage(<%=pageDivision.getCurPage() + 1%>,<%=pageDivision.getTotalPageNum()%>)">
										<img align="absmiddle" src="img/arrow_right.gif" /> </a>
									<a
										onclick="onPage(<%=pageDivision.getTotalPageNum()%>,<%=pageDivision.getTotalPageNum()%>)">
										<img align="absmiddle" src="img/arrow_last.gif" /> </a>
									<%
										}
									%>
								</div>

							</div>

							<div id="CntHeader" class="secondLine">
								<table width="100%">
									<tr>
										<td width="40">
											<input type="button" value="删除所选" onclick="onDelete()" />
										</td>
										<td>
											<input type="button" value="添加" onclick="onAdd()" />
										</td>
									</tr>
								</table>
								<table width="100%">
									<tr>
										<input type="hidden" name="sortKey" id="sortKey" />
										<td width="2%">
											<input type="checkbox" onclick="onAllCheck()" id="allCheck" />
										</td>
										<td width="40%">
											<a onclick="onSort('fileName')" title="单击按文件名排序"> 文件名 <%
												if (request.getParameter("sortKey") == null
														|| request.getParameter("sortKey").equals("0fileName")) {
											%>
												<img src="img/sortarrowup.gif" alt="ascending" /> <%
 	} else if (request.getParameter("sortKey").equals("1fileName")) {
 %>
												<img src="img/sortarrowdown.gif" alt="descending" /> <%
 	}
 %>
											</a>
										</td>
										<td width="20%">
											<a onclick="onSort('createTime')" title="单击按创建时间排序">
												创建时间 <%
												if (request.getParameter("sortKey") != null
														&& request.getParameter("sortKey").equals("0createTime")) {
											%>
												<img src="img/sortarrowup.gif" alt="ascending" /> <%
 	} else if (request.getParameter("sortKey") != null
 			&& request.getParameter("sortKey").equals("1createTime")) {
 %>
												<img src="img/sortarrowdown.gif" alt="descending" /> <%
 	}
 %>
											</a>
										</td>
										<td width="15%">
											<a onclick="onSort('touchNum')" title="单击按访问次数排序"> 访问次数
												<%
												if (request.getParameter("sortKey") != null
														&& request.getParameter("sortKey").equals("0touchNum")) {
											%>
												<img src="img/sortarrowup.gif" alt="ascending" /> <%
 	} else if (request.getParameter("sortKey") != null
 			&& request.getParameter("sortKey").equals("1touchNum")) {
 %>
												<img src="img/sortarrowdown.gif" alt="descending" /> <%
 	}
 %>
											</a>
										</td>
										<td width="15%">
											<a onclick="onSort('downloadNum')" title="单击按下载次数排序">
												下载次数 <%
												if (request.getParameter("sortKey") != null
														&& request.getParameter("sortKey").equals("0downloadNum")) {
											%>
												<img src="img/sortarrowup.gif" alt="ascending" /> <%
 	} else if (request.getParameter("sortKey") != null
 			&& request.getParameter("sortKey").equals("1downloadNum")) {
 %>
												<img src="img/sortarrowdown.gif" alt="descending" /> <%
 	}
 %>
											</a>
										</td>
										<td width="8%" style="color:#0000FF;font-weight:600;">属性</td>
									</tr>
								</table>
								<script type="text/javascript">
						  <%if (request.getParameter("sortKey") == null) {%>
							document.getElementById("sortKey").value = "0fileName";
						  <%} else {%>
							document.getElementById("sortKey").value = "<%=request.getParameter("sortKey")%>";
						  <%}%>
						</script>
							</div>

							<div id="CntMid">
								<%
									Iterator iterator = pageDivision.getitemList().iterator();
									while (iterator.hasNext()) {
										ResItem item = (ResItem) iterator.next();
								%>
								<table width="100%">
									<tr>
										<td width="2%">
											<input type="checkbox" name="itemCheckBox"
												id="<%=item.getID()%>" onclick="onOneCheck()" />
										</td>
										<td width="40%">
											<a> <%=item.getFileName()%></a>
										</td>
										<td width="20%">
											<%=item.getSubmitTime()%>
										</td>
										<td width="15%">
											<%=item.getTouchNum()%>
										</td>
										<td width="15%">
											<%=item.getDownloadNum()%>
										</td>
										<td>
											<a id="btn<%=item.getID()%>" style="cursor:pointer; color:blue;"
												onclick="showDescription(<%=item.getID()%>)">显示</a><!--此处结束标签切记不可换行-->
										</td>
									</tr>
								</table>
								<div id="table<%=item.getID()%>"
									style="display:none; margin:5px 30px 5px 30px; padding:5px; overflow:hidden;
									border:dotted 1px #0000FF; color:#0000FF; ">
									<%=item.getDescription()%>
								</div>
								<%
								 }
								%>
								
							</div>
							<div id="CntFooter">
							</div>
						</td>
					</tr>
				</table>

				<div id="BottomLine"></div>

			</form>
		</div>

		<div id="Footer">
			<table width="100%">
				<tr>
					<td>
						<a href="../index.jsp">返回前台</a>
						<s:a action="init.action" namespace="/">论坛学习</s:a>
						<a href="http://www.nankai.edu.cn" target="view_window">南开大学</a>
						<a href="http://cs.nankai.edu.cn" target="view_window">软件学院</a>
						<a href="http://soft.nankai.edu.cn" target="view_window">软件之家</a>
						<a href="http://music.nankai.edu.cn" target="view_window">世外桃源</a>
						<a href="http://movie.nankai.edu.cn" target="view_window">光影传奇</a>
						<a href="http://music.nankai.edu.cn" target="view_window" style="border-right: none;">联系我们</a>
					</td>
				</tr>
				<tr>
					<td>
						<p style="float:left; margin-top: 5px; margin-left: 300px; color: #3a91b8;">版权所有@南开大学软件学院</p>
						<p style="margin-top: 5px; margin-right: 200px; color: #3a91b8;">联系地址：天津市南开区卫津路94号南开大学13宿</p>	
					</td>
				</tr>
			</table>
		</div>

	</body>
</html>